package com.megvii.koala.data.filter;

import java.util.List;

/**
 * Created by linyue on 15/12/31.
 */
public class CollectionFilter
{
    public static <T, L extends List> List<T> filterList(List<T> list, Class<L> returnClass,
            ObjectFilter<T> comparator)
    {
        try
        {
            L result = returnClass.newInstance();
            for (T object : list)
            {
                if (comparator.filter(object))
                {
                    result.add(object);
                }
            }
            return result;
        }
        catch (InstantiationException e)
        {
            e.printStackTrace();
        }
        catch (IllegalAccessException e)
        {
            e.printStackTrace();
        }
        return null;
    }
}
